package cn.edu.hbwe.book.servlet.client;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.hbwe.book.entity.User;
import cn.edu.hbwe.book.exception.UpdateUserInfoException;
import cn.edu.hbwe.book.service.UserService;
/**
 * Servlet implementation class UpdateUserInfoServlet
 */
@WebServlet("/updateUserInfo")
public class UpdateUserInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		User user = (User) request.getSession().getAttribute("user");
		UserService service = new UserService();
		try {
			service.updateUserInfo(user.getId(),request.getParameter("password"),request.getParameter("gender"),request.getParameter("telephone"));
			// 获取session对象
			HttpSession session = request.getSession();
			// 销毁session
			session.invalidate();
			response.sendRedirect(request.getContextPath() + "/client/updateUserInfosuccess.jsp");
		} catch (UpdateUserInfoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
